<?php 
header("content-type:text/html;charset=utf8");
include_once("Classes/PHPExcel.php");
$pdo = new PDO("mysql:host=127.0.0.1;dbname=07c","root","root");
$sql = "select * from yuan";
$res = $pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
// print_r($res);die;
$excel = new PHPExcel();
$sheet = $excel ->setActiveSheetIndex(0)
				->setCellValue('A1', 'ID')
	            ->setCellValue('B1', '用户名')
	            ->setCellValue('C1', '密码')
	            ->setCellValue('D1', '真实姓名')
	            ->setCellValue('E1', '薪资');

$i=2;
foreach ($res as $key => $value) {
	$sheet = $excel ->getActiveSheet()
					->setCellValue('A'.$i, $value['id'])
		            ->setCellValue('B'.$i, $value['names'])
		            ->setCellValue('C'.$i, $value['pwd'])
		            ->setCellValue('D'.$i, $value['realname'])
		            ->setCellValue('E'.$i, $value['money']);
		            $i++;
}
$excel->getActiveSheet()->setTitle("员工工资详情");
// Redirect output tso a client’s web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="员工工资详情.xlsx"');
header('Cache-Control: max-age=0');


$objWriter = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
$objWriter->save('php://output');

 ?>